/**
 * Created by Dalyn on 2017/3/16.
 * 产品-列表信息组件
 */

import React, {Component}from 'react';
import ReactKey from "../../util/ReactKey"

export default class Product_item extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            flag: false
        };
        this.partyBEnid = ''
    }

    componentWillMount() {
        // this.partyBEnid = this.props.item.partyBEnid
    }

    onchose() {

    }

    unchose() {
        this.refs._radioBtn.checked = false
        // this.setState={
        //     flag:false
        // };
    }

    ontouch() {
        /*每条item都有一个自己的状态值*/
        this.setState({
            flag: this.refs._radioBtn.checked
        }, () => {
            // debugger
            let isSelectAll = this.refs._radioBtn.checked;
            if (!isSelectAll) {
                this.props._isallclick(isSelectAll)
            }
        })
    }

    /*产品对应字段*/
    goodsInfoList() {
        let goodsProperty = this.props.goodsProperty.split(",");
        return goodsProperty.map((item, index) => {
            if (index == goodsProperty.length - 1) {
                return (
                    <span className="product_set_nor product_set_ts2_last product_title"
                          style={{width: (1070 - goodsProperty.length) / (goodsProperty.length) + "px"}}
                          key={ReactKey.key} title={this.props.goodsItem[item]}>{this.props.goodsItem[item]}</span>
                )
            } else {
                return (
                    <span className="product_set_nor product_set_ts2 product_title"
                          style={{width: (1070 - goodsProperty.length) / (goodsProperty.length) + "px"}}
                          key={ReactKey.key} title={this.props.goodsItem[item]}>{this.props.goodsItem[item]}</span>
                )
            }
        })
    }

    render() {
        const {index} = this.props;
        if (index % 2 === 0) {
            return (
                <li className={this.props.goodsItem.isImport == 1 ? "product_set_tb product_isImport" : "product_set_tb"}>
                <span className="product_set_nor product_set_ts0">
                    <label className="checkbox_cover--label">
                        <span className="checkbox_cover--box">
                            <input className="checkbox_cover--style" type="checkbox" ref={"_radioBtn"}
                                           onChange={this.ontouch.bind(this)}
                                           disabled={this.props.goodsItem.isImport == 1 ? "disabled" : ""}/>
                            <span data-checkbox="cover"></span>
                        </span>
                        {/*<span className="checkbox_cover--title"></span>*/}
                    </label>
                </span>
                    <span className="product_set_nor product_set_ts1">{parseInt(this.props.index + 1)}</span>
                    {
                        this.goodsInfoList()
                    }
                </li>
            );
        } else {
            return (
                <li className={this.props.goodsItem.isImport == 1 ? "product_set_tbb product_isImport" : "product_set_tbb"}>
                <span className="product_set_nor product_set_ts0">
                    <label className="checkbox_cover--label">
                        <span className="checkbox_cover--box">
                            <input className="checkbox_cover--style" type="checkbox" ref={"_radioBtn"}
                                           onChange={this.ontouch.bind(this)}
                                           disabled={this.props.goodsItem.isImport == 1 ? "disabled" : ""}/>
                            <span data-checkbox="cover"></span>
                        </span>
                        {/*<span className="checkbox_cover--title"></span>*/}
                    </label>
                </span>
                    <span className="product_set_nor product_set_ts1">{parseInt(this.props.index + 1)}</span>
                    {
                        this.goodsInfoList()
                    }
                </li>
            );
        }

    }
}